#ifndef CBEAM_H
#define CBEAM_H

#include "CVector3d.h"
#include "particle.h"
//#include "CSpaceCharge.h"
#include <vector>
#include <string>
#include "CLHEP/Matrix/Vector.h"
using namespace std;
const double clight=2.99792458e8;
const double pi=3.1415926;

class CBeam{
  public:
    CBeam();
    ~CBeam();
//    void                       CalSC();
//    void                       SetSC();
    void                       setBeam(double, double, double, double, double, double, double, double, double, int,double, double, double);
    void                       beamDistribution(int);
    void                       beamDistribution(string);
    CVector3d                  getRMSEmittance() const;
    void                       setAlph(double, double, double);
    void                       setBeta(double, double, double);
    void                       setEmittance(double, double, double);
    void                       setStep(double);
    double                     getStep() const;
    CVector3d                   getAlph() const;
    CVector3d                   getBeta() const;
    CVector3d                   getEmittance() const;
    CVector3d                   getRMSSize() const;
    CVector3d                   getAveSize() const;
    int                        getParticleNumber() const;
    double                     getCurrent() const;
    double                     getDutyFactor() const;
    void                       plotBeam( );
    void                       getSelfForce(CVector3d);
//    vector<vector<double> >*   getBeam();
    void                       getBeam();
    std::vector<particle>      p;
    void                         calRms();
    void                       setEnergy(double);
    double                     getEnergy();
    void                       setFreq(double);
    double                     getFreq();
    vector<double>&            getBeamSize();
    //============test==========================
    void                       setEs(double);
    void                       setPhis(double);
    //=========end just test====================
  private:
    void                       uniformDis();
    void                       kvDis();
    void                       wbDis();
    void                       oneStep();
  private:
  //just test===================================
  double dPhiS,dEs;
  //end just test===============================
//    CSpaceCharge               cSc;
    int                        particleNumber;
    CVector3d                   alph;
    CVector3d                   beta;
    CVector3d                   emittance;
    CVector3d                   EmitRms;
    CVector3d                   RmsSize;
    CVector3d                   AveSize;
//    CVector3d                   MaxSize;  //envelop
    vector<double>              vdBeamSize;  
    vector<vector<double> >     vvdBeam;
    //CSpaceCharge                Sp;
    //all the beam size results stored in hvSize,include velocity and position of beam center
    //Rms beamsize,envelopsize,rms emittance, total emittance.
    //the beam size mean x y z in cm,xp,yp,zp in mrad, dphi in deg, dE in MeV, 
    //all the values measured in beam frame
    int                        gridX;
    int                        gridY;
    int                        gridZ;
    double                     current;
    double                     dutyFactor;
    double                     dStep;
    double                        dXAve,dYAve,dZAve,dXpAve,dYpAve,dZpAve; 
    double                        dXRms,dYRms,dZRms,dXpRms,dYpRms,dZpRms; 
  //  double                        dpOverPRms,dPhiRms,dDEnergyRms;
    double                        dEnergy,dErest;
    double                        dFreq;
    vector<vector<double> >       vvdParticleState;
};
#endif
